package cn.hallele.bbts.core.component.aspect;

import cn.hallele.bbts.core.common.annotations.Log;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * LogAspect
 *
 * @author anle5
 * @since 2023/12/10 星期日 18:36
 */
@Slf4j
@Aspect
@Component
public class LogAspect {
    /**
     * cut
     */
    @Pointcut(value = "@annotation(cn.hallele.bbts.core.common.annotations.Log)")
    public void cut() {
    }


    /**
     * 拦截所有cn.hallele.bbts下的controller
     *
     * @param joinPoint joinPoint
     * @return Object
     * @throws Throwable 业务中的异常，往上抛，交给ExceptionAspect处理
     */
    @Around("cut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        Object response = joinPoint.proceed();
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Method method = signature.getMethod();
        Log annotation = method.getAnnotation(Log.class);


        return response;
    }
}
